#include <stdio.h>

int winer(char s1,char s2){
	if( s1==s2 ){
		return 0;
	}
	if( s1=='B'&&s2=='C'){
		return 1;
	} 
	if( s1=='C'&&s2=='J' ){
		return 1;
	}
	if( s1=='J'&&s2=='B' ){
		return 1; 
	}
	return -1;
}
int max(int a,int b){
	return a>b?a:b;
}

int main(){
	int n,r1[3]={0},r2[3]={0},c1=0,j1=0,b1=0,c2=0,j2=0,b2=0;
	char char1,char2;
	scanf("%d",&n);
	for( int i=0; i<n; i++ ){
		scanf(" %c %c",&char1,&char2);
		if( winer(char1,char2)==1 ){
			r1[0]++;r2[2]++;
			switch ( char1 ){
				case'C':c1++;break;
				case'B':b1++;break;
				case'J':j1++;break;
			}
		}
		if( winer(char1,char2)==-1 ){
			r2[0]++;r1[2]++;
			switch ( char2 ){
				case'C':c2++;break;
				case'B':b2++;break;
				case'J':j2++;break;
			}
		}
		if( winer(char1,char2)==0 ){
			r1[1]++;r2[1]++;
		}
	}
	printf("%d %d %d\n",r1[0],r1[1],r1[2]);
	printf("%d %d %d\n",r2[0],r2[1],r2[2]);
	int flag=0; 
	if( flag==0&&b1==max(max(c1,b1),j1) ){
		printf("B ");flag=1;
	}
	if( flag==0&&c1==max(max(c1,b1),j1) ){
		printf("C ");flag=1;
	}
	if( flag==0&&j1==max(max(c1,b1),j1) ){
		printf("J ");flag=1;
	}

	flag=0;
	if( flag==0&&b2==max(max(c2,b2),j2) ){
		printf("B");flag=1;
	}
	if( flag==0&&c2==max(max(c2,b2),j2) ){
		printf("C");flag=1;
	}
	if( flag==0&&j2==max(max(c2,b2),j2) ){
		printf("J");flag=1;
	}
	
	return 0;
}
